//
//  HomeTableViewController.m
//  CD1505WeiBo
//
//  Created by 千锋 on 15/12/29.
//  Copyright (c) 2015年 LiChaoRan. All rights reserved.
//

#import "HomeTableViewController.h"
#import "UIBarButtonItem+Util.h"

#import "DropControl.h"

#import "TitleButton.h"

@interface HomeTableViewController ()

@property(nonatomic,strong)DropControl *dropControl;//下拉框

@end

@implementation HomeTableViewController

//懒加载
- (DropControl *)dropControl{
    if (!_dropControl) {
        NSArray *dataArray=@[];
        _dropControl=[[DropControl alloc]initWithInsideViewFrame:CGRectMake(100, 60, 180, 300) inView:self.tabBarController.view dataSource:dataArray];
        
        __weak typeof(self) weakSelf=self;
        _dropControl.aftBlock=^{
            //隐藏回调
            TitleButton *btn=(TitleButton *)weakSelf.navigationItem.titleView;
            if (btn.selected) {
                btn.selected=NO;
            }
        };
    }
    return _dropControl;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    [self createNaviBarItem];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 0;
}

//构建导航按钮
- (void)createNaviBarItem{
    self.navigationItem.leftBarButtonItem=[UIBarButtonItem generateBarButtonItemWithNormalImageName:@"navigationbar_friendattention" ilightedImageName:@"navigationbar_friendattention_highlighted"];
    self.navigationItem.rightBarButtonItem=[UIBarButtonItem generateBarButtonItemWithNormalImageName:@"navigationbar_icon_radar" ilightedImageName:@"navigationbar_icon_radar_highlighted"];
    
    TitleButton *btn=[TitleButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"123" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.backgroundColor=[UIColor clearColor];
    [btn setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];
    btn.frame=CGRectMake(0, 0, 200, 30);
    
    self.navigationItem.titleView=btn;
    
    [btn addTarget:self action:@selector(titleBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
}

//按钮点击
- (void)titleBtnPressed:(UIButton *)sender{
    sender.selected=!sender.selected;
    
    if (sender.selected) {
        [self.dropControl show];
    }
    else{
        [self.dropControl disMiss];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
}

@end
